package security.Authorization.UserRole;

import security.Authentication.Base.IdentifiedUser;
import security.Authentication.Base.UnknownUser;
import security.Authentication.Base.User;
import security.Authorization.Base.AuthorizationHandler;
import security.Authorization.Base.AuthorizationLevel;

public class UserRole implements AuthorizationHandler {

	@Override
	public void authorize(User user) {
		if (user instanceof IdentifiedUser) {
			IdentifiedUser identifiedUser = (IdentifiedUser)user;
			
			if(identifiedUser.getLevel() == AuthorizationLevel.ADMIN){
				this.isAdmin(identifiedUser);
			}
			if(identifiedUser.getLevel() == AuthorizationLevel.GUEST){
				this.isGuest(identifiedUser);
			}
			if(identifiedUser.getLevel() == AuthorizationLevel.USER){
				this.isUser(identifiedUser);
			}
			if(identifiedUser.getLevel() == AuthorizationLevel.NONE){
				this.isNone(identifiedUser);
			}
		} else if (user instanceof UnknownUser) {
			UnknownUser unknownUser = (UnknownUser)user;
			this.isUnknown(unknownUser);
			
		} else {
			System.out.println("Show nothing");
		}
	}
	
	public void isAdmin (User user){
		System.out.println("Show everything");
	}
	
	public void isGuest (User user){
		System.out.println("Show limited");
	}
	
	public void isUser (User user){
		System.out.println("Show account");
	}
	
	public void isNone (User user){
		System.out.println("Show nothing");
	}
	
	public void isUnknown (User user){
		UnknownUser unknownUser = (UnknownUser)user;
		System.out.println("Show nothing because: " + unknownUser.getCause());
	}
}
